<template>
  <div
    @click="change"
    style="display: flex;"
  >
    <div class="input_url">
      <i :class="getMessge.icon"></i>
      <div>
        <div
          class="url_title"
          :title="getMessge.title"
        >{{ getMessge.title }}</div>
        <div>{{ type }}
          <span class="hint">打开</span>
        </div>
      </div>
      <i
        v-if="close !== false"
        @click.stop="$emit('close')"
        class="el-icon-circle-close"
      ></i>
    </div>
  </div>
</template>

<script>
export default {
  props: ["fileLink", "fileName","filePath", "type", "close"],
  computed: {
    // get icon and title
    getMessge() {
      if (this.type === "UPLOAD") {
        return {
          title: this.fileName,
          icon: "el-icon-document-remove",
        };
      } else if (this.type === "LINK") {
        return {
          title: this.fileLink,
          icon: "el-icon-link",
        };
      }  else if (this.type === "OWN_WEB_URL") {
        return {
          title: this.fileLink,
          icon: "el-icon-link",
        };
      }  else if (this.type === "OWN_FILE_URL") {
        return {
          title: this.fileName,
          icon: "el-icon-document-remove",
        };
      }
    },
  },
  methods: {
    change() {
      if (this.type === "UPLOAD") {
        window.open(this.$config.imgUrl+this.filePath);
      } else if (this.type === "LINK") {
        window.open(this.fileLink);
      }  else if (this.type === "OWN_WEB_URL") {
        window.open(this.fileLink);
      } else if (this.type === "OWN_FILE_URL") {
        window.open(this.$config.imgUrl+this.filePath);
      }
      this.$emit('change')
    },
  },
};
</script>

<style lang="scss" scoped>
.input_url {
  &:hover {
    .hint {
      display: inline-block;
    }
  }
  cursor: pointer;
  background-color: #ececec;
  border-radius: 10px;
  padding: 15px;
  display: flex;
  align-items: center;
  .el-icon-link,
  .el-icon-document-remove {
    font-size: 26px;
    margin-right: 10px;
  }
  .url_title {
    max-width: 300px;
    white-space: nowrap; /* 防止文本换行 */
    overflow: hidden; /* 隐藏超出容器的部分 */
    text-overflow: ellipsis; /* 用省略号表示被裁剪的文本 */
  }
  .el-icon-circle-close {
    font-size: 18px;
    margin-left: 10px;
    cursor: pointer;
    color: #999;
    &:hover {
      color: red;
    }
  }
  .hint {
    display: none;
    font-size: 12px;
  }
}
</style>
